package cn.iocoder.yudao.module.mybusiness.controller.admin;


import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.mybusiness.domain.BussinessMod;
import cn.iocoder.yudao.module.mybusiness.domain.Task;
import cn.iocoder.yudao.module.mybusiness.param.ModParam;
import cn.iocoder.yudao.module.mybusiness.param.TaskParam;
import cn.iocoder.yudao.module.mybusiness.service.TaskService;
import io.swagger.v3.oas.annotations.Operation;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.security.PermitAll;
import javax.validation.Valid;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.error;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@RestController
@RequestMapping("/task")
public class TaskController {


    @Autowired
    private TaskService taskService;

    @GetMapping("/getList")
    @Operation(summary = "获取任务列表")
//    @PermitAll
    public CommonResult<PageResult<Task>> getList(TaskParam taskParam){
        PageResult<Task> pageResult = taskService.getList(taskParam);
        return success(pageResult);
    }


    @PostMapping("/create")
    @Operation(summary = "新增任务")
//    @PermitAll
    public CommonResult<Boolean> create(@RequestBody Task task){
        taskService.create(task);
        return success(true);
    }

    @GetMapping("/delete")
    @Operation(summary = "删除任务")
//    @PermitAll
    public CommonResult<Boolean> delete(@RequestParam Long id){
        try {
            taskService.delete(id);
            return success(true);
        } catch (Exception e) {
            e.printStackTrace();
            return error(430,e.getMessage());
        }
    }
}
